
*-----------------------------------------------------------------------------
**                       Does a UBI affect voter turnout                   **
**                     Produce Individual-Level Data File                   **
*-----------------------------------------------------------------------------

*** Individual level data 

use "cps_00017.dta"


gen fip=statefip
label val fip
label var fip "State (FIPS code)"

*no cpsidp for age<14 1976-82; only interested in voting hence delete all minors
drop if age<18

gen t=.
replace t=1 if year==1978
replace t=2 if year==1980
replace t=3 if year==1982
replace t=4 if year==1984
replace t=5 if year==1986
replace t=6 if year==1988
replace t=7 if year==1990
replace t=8 if year==1992
replace t=9 if year==1994
replace t=10 if year==1996
replace t=11 if year==1998
replace t=12 if year==2000
label var t "time"

gen id=.
replace id=1 if fip==1
replace id=2 if fip==2
replace id=3 if fip==4
replace id=4 if fip==5
replace id=5 if fip==6
replace id=6 if fip==8
replace id=7 if fip==9
replace id=8 if fip==10
replace id=9 if fip==11
replace id=10 if fip==12
replace id=11 if fip==13
replace id=12 if fip==15
replace id=13 if fip==16
replace id=14 if fip==17
replace id=15 if fip==18
replace id=16 if fip==19
replace id=17 if fip==20
replace id=18 if fip==21
replace id=19 if fip==22
replace id=20 if fip==23
replace id=21 if fip==24
replace id=22 if fip==25
replace id=23 if fip==26
replace id=24 if fip==27
replace id=25 if fip==28
replace id=26 if fip==29
replace id=27 if fip==30
replace id=28 if fip==31
replace id=29 if fip==32

replace id=30 if fip==33
replace id=31 if fip==34
replace id=32 if fip==35
replace id=33 if fip==36
replace id=34 if fip==37
replace id=35 if fip==38
replace id=36 if fip==39
replace id=37 if fip==40
replace id=38 if fip==41
replace id=39 if fip==42

replace id=40 if fip==44
replace id=41 if fip==45
replace id=42 if fip==46
replace id=43 if fip==47
replace id=44 if fip==48
replace id=45 if fip==49
replace id=46 if fip==50
replace id=47 if fip==51
replace id=48 if fip==53
replace id=49 if fip==54
replace id=50 if fip==55
replace id=51 if fip==56
label var id "State ID"


*age
rename age age_raw
gen age = age_raw
label var age "Age raw"
recode age 18/24=1 25/34=2 35/44=3 45/54=4 55/64=5 65/99=6, generate (agegroup)
label define agegroup 1 "18–24" 2 "25–34" 3 "35–44" 4 "45–54" 5 "55–64" 6 "65+"
label values agegroup agegroup
label var agegroup "Age group"

*sex 
rename sex sex_raw
gen female=sex_raw
recode female(2=1)(1=0)
label define gender 1 "Female" 0 "Male"
label var female gender
label var female "Female"

*race
rename race race_raw
gen race4=race_raw
label var race4
recode race4 (100=1)(200=2)(300=5)(650=4)(700=5)
label define ra 1 "White" 2 "Black" 4 "Asian" 5 "Other"
label values race4 ra
label var race4 "Race 4"

gen race5=race_raw
label var race5 "Race 5"
recode race5 (100=1)(200=2)(300=3)(650=4)(700=5)
label define race5 1 "White" 2 "Black/Negro" 3 "American Indian/Aleut/Eskimo" 4 "Asian or Pacific Islander" 5 "Other (single) race, n.e.c." 
label values race5 race5

*hisp 
rename hispan hispan_raw
gen hisp=hispan_raw
label val hisp
recode hisp (901=.)(902=.)
recode hisp (100=1)(102=1)(103=1)(104=1)(108=1)(200=1)(300=1)(600=1)(610=1)
label define hi 0 "Not Hispanic" 1 "Hispanic" 
label values hisp hi
label var hisp "Hispanic origin"

*empstat
rename empstat empstat_raw
gen empstat=empstat_raw
recode empstat (0=.)(1=1)(10=2)(12=2)(20=3)(21=3)(22=3)(30=4)(31=4)(32=4)(33=4)(34=4)(35=4)(36=4)
label define emp 1 "Armed Forces" 2 "Employed" 3 "Unemployed" 4 "NILF"
label values empstat emp
label var empstat "Employment status"

*educ
rename educ educ_raw
gen educ=educ_raw
label val educ
recode educ (1=.) (999=.)(2=0)(10=1)(11=1)(12=1)(13=1)(14=1)(20=2)(21=2)(22=2)(30=2)(31=2)(32=2)(40=3)(50=3)(60=3)(70=4)(71=4)(72=4)(73=4)(80=5)(81=5)(90=5)(91=5)(92=5)(100=5)(110=6)(111=6)(120=7)(121=7)(122=7)(123=7)(124=7)(125=7)
label define educc 0 "None" 1 "Grade 1-4" 2 "Grade 5-8" 3 "Grade 9-11" 4 "High School" 5 "Some college" 6 "BA Degree" 7 "Post-Grad"
label values educ educc
label var educ "Educational attainment"

*voted
rename voted voted_raw
gen voted=voted_raw
label val voted
recode voted(1=0)(2=1)(96=.a)(97=.b)(98=.c)(99=.d)
label define vote 0 "Did not vote" 1 "Voted" .a "Refused" .b "Don't know" .c "No response" .d "Not in universe"
label values voted vote
label var voted "Voted for the most recent November election"


merge m:1 year id using data_ubiturnout_aggregate.dta, keepusing(treatyear alaska dividend dividend_nominal dividend_real div1000 dividend_nominal_interaction dividend_real_interaction div1000_interaction lnpop gini lnrgdp_pc edr)

drop _merge

save data_ubiturnout_individual.dta, replace
